package game.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sghd.common.utils.json.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.rmi.runtime.Log;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fank
 * @date 2018-08-20 12:55
 * @desc
 **/
public class Result {
    private Logger logger = LoggerFactory.getLogger(getClass());
    /** 中的线*/
    private Map<Integer, List<Integer>> lines = new HashMap<>();
    /** 每一列的填充数据<1，2，3 >*/
    private Map<Integer, List<Integer>> fills = new HashMap<>();
    /** 每一列填充数据的索引*/
    @JsonIgnore
    private Map<Integer, List<Integer>> fillsGrid = new HashMap<>();

    private long totalFen;

    public void added(int line, List<Integer> list, long fen) {
        lines.put(line, list);
        totalFen += fen;
    }

    /**是否消除成功*/
    @JsonIgnore
    public boolean isElimit() {
        return !lines.isEmpty();
    }

    /**
     * 每一列要填充的格子索引
     * */
    public void addFillsGrid(int col, List<Integer> indexs) {
        fillsGrid.put(col, indexs);
    }

    /**
     * 每一列要填充的元素是干什么
     * */
    public void addFill(int col, List<Integer> fills) {
        this.fills.put(col, fills);
    }

    public Map<Integer, List<Integer>> getFills() {
        return fills;
    }

    public void setFills(Map<Integer, List<Integer>> fills) {
        this.fills = fills;
    }

    public long getTotalFen() {
        return totalFen;
    }

    public void setTotalFen(long totalFen) {
        this.totalFen = totalFen;
    }

    public Map<Integer, List<Integer>> getFillsGrid() {
        return fillsGrid;
    }

    public void setFillsGrid(Map<Integer, List<Integer>> fillsGrid) {
        this.fillsGrid = fillsGrid;
    }

    public void print() {
        if (!logger.isDebugEnabled()) {
            return;
        }
        System.out.println("中[" + lines.size() + "]条线");
        for (Integer linIdx : lines.keySet()) {
            System.out.println("LINE:" + linIdx);
            System.out.println(JsonUtils.object2String(lines.get(linIdx)));
        }
    }

    public Map<Integer, List<Integer>> getLines() {
        return lines;
    }

    public void setLines(Map<Integer, List<Integer>> lines) {
        this.lines = lines;
    }
}
